import request from "@/utils/request";

let cacheCostType = [];

export default {
  name: 'CostTypeMixin',
  data(){
    return {
      allCostType: [], // 所有代理
    }
  },
  computed: {

  },
  created(){
    this.getAllCostType();
  },
  methods: {
    getAllCostType(){
      if(cacheCostType.length > 0){
        this.allCostType = cacheCostType
      }else{
        request({
          url: '/cost/getAllCostType'
        })
          .then(res=>{
            this.allCostType = res.data
            cacheCostType = res.data
          })
      }
    },
    getCostTypeNameByType(type){
      let typeName = '';
      this.allCostType.some(item=>{
        if(item.type === type){
          typeName = item.name;
          return true
        }
        return false
      })
      return typeName;
    }
  }
}

